Parallel partition-wise joins

ABSTRACT

Techniques are disclosed for expanding the concept of partitioning in variety of ways. In particular techniques are provided for performing multiple-dimension partitioning. In multiple-dimension partitioning, a database object is divided into partitions based on one criteria, and each of those resulting partitions is divided into sub-partitions based on a second criteria. The process of partitioning partitions based on different criteria may be repeated across any number of dimensions. Entirely different partitioning techniques may be used for each level of partitioning. The database server takes advantage of partitions when processing queries that include joins. In particular, techniques are provided for performing a full parallel partitioned-wise join, and a partial parallel partition-wise join. In a partial parallel partition-wise join, one of the join tables is statically partitioned on the join key and another join table is dynamically partitioned in a way that corresponds to the partition criteria of the statically partitioned table. In a full parallel partition-wise join, both of the tables involved in the join have already been statically partitioned based on the same criteria. The join operation is performed in parallel in a way that takes advantage of that static partitioning.

FIELD OF THE INVENTION

The present invention relates to computer systems and, moreparticularly, to techniques for performing joins between objects withincomputer systems.

BACKGROUND OF THE INVENTION

In conventional relational database tables, rows are inserted into thetable without regard to any type of ordering. Consequently, when a usersubmits a query that selects data from the table based on a particularvalue or range of values, the entire table has to be scanned to ensurethat all rows that satisfy the criteria are identified. Partitioning isa technique that, in certain situations, avoids the need to search anentire table (or other database object).

With partitioning, an object, such as a database table, is divided upinto sub-tables, referred to as “partitions”. The most common form ofpartitioning is referred to range partitioning. With range partitioning,each individual partition corresponds to a particular range of valuesfor one or more columns of the table. For example, one column of a tablemay store date values that fall within a particular year, and the tablemay be divided into twelve partitions, each of which corresponds to amonth of that year. All rows that have a particular month in the datecolumn would then be inserted into the partition that corresponds tothat month. In this example, partitioning the table will increase theefficiency of processing queries that select rows based on the monthcontained in the date column. For example, if a particular queryselected all rows where months equals January, then only the partitionassociated with the month of January would have to be scanned.

Typically, the criteria used to partition a database object is specifiedin the statement that creates the database object. For example, thefollowing Structured Query Language SQL) statement creates a table“sales” that is range partitioned based on date values contained in acolumn named “saledate”:

create table sales

(saledate DATE,

productid NUMBER, . . . )

partition by range (saledate)

partition sal94Q1 values less than to_ate (yy-mm-dd, ‘94-04-01’)

partition sal94Q2 values less than to_ate (yy-mm-dd, ‘94-07-01’)

partition sal94Q3 values less than to_ate (yy-mm-dd, ‘94-10-01’)

partition sal94Q4 values less than to_ate (yy-mm-dd, ‘95-01-01’)

Execution of this statement creates a table named “sales” that includesfour partitions: sal94Q1, sal94Q2, sal94Q3, and sal94Q4. The partitionnamed sal94Q1 includes all rows that have a date less than 94-04-01 intheir saledate column. The partition named sal94Q2 includes all rowsthat have a date greater than or equal to 94-04-01 but less than94-07-01 in their saledate column. The partition named sal94Q3 includesall rows that have a date greater than or equal to 94-07-01 but lessthan 94-10-01 in their saledate column. The partition named sal94Q4includes all rows that have a date greater than or equal to 94-10-01 butless than 95-01-01 in their saledate column.

When a database server receives a request to perform an operation, thedatabase server makes a plan of how to execute the query. If theoperation involves accessing a partitioned object, part of making theplan involves determining which partitions of the partitioned object, ifany, can be excluded from the plan (i.e. which partitions need not beaccessed to execute the query). The process of excluding partitions fromthe execution plan of a query that accesses a partitioned object isreferred to as “partition pruning”.

Unfortunately, conventional pruning techniques can only be applied to alimited set of statements. For example, the database server can performpartition pruning when the statement received by the database serverexplicitly limits itself to a partition or set of partitions. Thus, thedatabase server can exclude from the execution plan of the statement“select * from sales PARTITION(sal94Q1)” all partitions of the salestable other than the sal94Q1 partition.

The database server can also perform partition pruning on statementsthat do not explicitly limit themselves to particular partitions, butwhich select data based on the same criteria that was used to partitionthe partitioned object. For example, the statement:

select * from sales where saledate between (94-04-01) and (94-07-01)does not explicitly limit itself to particular partitions. However,because the statement limits itself based on the same criteria (saledatevalues) as was used to partition the sales table, the database server isable to determine, based on the selection criteria of the statement andthe partition definitions of the table, which partitions need not beaccessed during execution of the statement. In the present example, thedatabase server would be able to perform partition pruning that limitsthe execution plan of the statement to sal94Q2.

Similarly, database servers can perform partition pruning for querieswith WHERE clauses that (1) specify equalities that involve thepartition key (e.g. where saledate=94-02-05), (2) include IN lists thatspecify partition key values (e.g. where saledate IN (94-02-05,94-03-06)), and (3) include IN subqueries that involve the partition key(e.g. where salesdate in (select datevalue from T)).

Another form of partitioning is referred to as hash partitioning.According to hash partitioning, one or more values from each record areapplied to a hash function to produce a hash value. A separate partitionis established for each possible hash value produced by the hashfunction, and rows that hash to a particular value are stored within thepartition that is associated with that hash value. Similar to rangebased partitioning, hash partitioning increases the efficiency ofprocessing certain types of queries. For example, when a query selectsall rows that contain a particular value in the column that is used toperform the hash partitioning, the database server can apply the valuein the query to the hash function to produce a hash value, and thenlimit the scan of the table to the partition that corresponds to thehash value thus produced.

A table that is hash partitioned into four partitions may be created bythe following statement:

create table sales

(saledate DATE,

productid NUMBER, . . . )

partition by hash (saledate)

partitions 4;

Similar to range partitions, hash partitions may be used for querieswith WHERE clauses that (1) specify equalities that involve thepartition key, (2) include IN lists that specify partition key values,and (3) include IN subqueries that involve the partition key. However,unlike range-based partitioning, partition pruning cannot be performedfor statements with predicates that specify ranges of partition keyvalues. Consequently, hash-based partitioning is often used when thenature of the partition key is such that range-based queries areunlikely, such as when the partition key is “social security number”,“area code” or “zip code”.

Due to the benefits that result from partition pruning, it is clearlydesirable to provide techniques for performing partition pruning for awider variety of statements.

SUMMARY OF THE INVENTION

Techniques are provided to expand the concept of partitioning in varietyof ways. For example, both hash partitioning and range partitioning canbe characterized as single-dimension partitioning because they use asingle criteria to divide up the partitioned objects. One aspect of theinvention is to perform multiple-dimension partitioning. Inmultiple-dimension partitioning, a database object is divided intopartitions based on one criteria, and each of those resulting partitionsis divided into sub-partitions based on a second criteria. The processof partitioning partitions based on different criteria may be repeatedacross any number of dimensions. In addition, entirely differentpartitioning techniques may be used for each level of partitioning. Forexample, database objects may be partitioned across one dimension usingrange-based partitioning, and each of those range-based partitions maybe partitioned across another dimension using hash based partitioningtechniques.

Another aspect of this invention relates to how the database servertakes advantage of partitions when processing queries that includejoins. In particular, techniques are provided for performing a fullparallel partition-wise join, and a partial parallel partition-wisejoin. In a partial parallel partition-wise join, one of the join tablesis statically partitioned on the join key and another join table isdynamically partitioned in a way that corresponds to the partitioningcriteria of the statically partitioned table. In a full parallelpartition-wise join, both of the tables involved in the join havealready been statically partitioned on the join key based on the samecriteria. The join operation is performed in parallel in a way thattakes advantage of that static partitioning.

BRIEF DESCRIPTION OF THE DRAWINGS

The present invention is illustrated by way of example, and not by wayof limitation, in the figures of the accompanying drawings and in whichlike reference numerals refer to similar elements and in which:

FIG. 1 is a block diagram illustrating a composite partitioned tableaccording to an embodiment of the invention;

FIG. 2 is a block diagram illustrating tables partitioned in a mannerthat allows a full partition-wise join according to an embodiment of theinvention;

FIG. 3 is a block diagram illustrating tables involved in a partialparallel partition-wise join according to an embodiment of theinvention; and

FIG. 4 is a block diagram illustrating a computer system on whichembodiments of the invention may be implemented.

DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT

A method and apparatus for partitioning and partition pruning aredescribed. In the following description, for the purposes ofexplanation, numerous specific details are set forth in order to providea thorough understanding of the present invention. It will be apparent,however, to one skilled in the art that the present invention may bepracticed without these specific details. In other instances, well-knownstructures and devices are shown in block diagram form in order to avoidunnecessarily obscuring the present invention.

COMPOSITE PARTITIONING

Hash-based partitioning and range-based partitioning each have theirstrengths and weaknesses. For example, with range-based partitioning, itbecomes necessary to add new partitions when newly arriving rows havepartition key values that fall outside the ranges of existingpartitions. Under these circumstances, adding a new partition may beaccomplished by a relatively simple procedure of submitting an ADDPARTITION statement that specifies the range for the new partition. Thedata in the existing partitions would remain intact.

In contrast, all partition key values fall within existing partitions ofa hash-partitioned table. However, it may be desirable to add newpartitions to a hash-partitioned table, for example, to spread the dataover a greater number of devices. Adding new partitions to ahash-partitioned table is an extremely expensive operation, since thedata in the existing partitions has to be completely redistributed basedon a new hash function.

Range-based partitions tend to be unevenly populated (skewed) relativeto hash-based partitions. For example, in a month-partitioned table, aparticular month may have ten times the sales of another month.Consequently, the partition containing the data for the particular monthwill contain ten times the data of the other month. In contrast, thevolume of data within one hash-based partition of an object tends tostay approximately in sync with the volume of the other hash-basedpartitions of the object. According to one embodiment of the invention,a partitioning technique is provided in which the benefits of both hashand range-based partitioning may be achieved. The technique, referred toherein as composite partitioning, involves creating partitions ofpartitions. For example, a table may be partitioned using range-basedpartitioning to create a set of first-level partitions. A hash functionmay then be applied to each of the first-level partitions to create, foreach first level partition, a set of second-level partitions. Further,the partitioning key used to create the partitions at one level may bedifferent than the partitioning key used to create the partitions atother levels.

Referring to FIG. 1, it illustrates a table 102 that has beenpartitioned using composite partitioning. At the first level, table 102has been partitioned using range-based partitioning on the first-levelkey “saledate”. At the second level, each partition created at the firstlevel has been partitioned using hash-based partitioning on thesecond-level partitioning key “productid”.

When a row is inserted into a composite partitioned table, the databaseserver must determine where to store the row. At each level ofpartition, the database server determines the appropriate partition forthe row based on the partitioning rules that apply to that level, andthe value that the row has for the partitioning key used at that level.For example, assume that a row is being inserted into table 102 and thatwithin the row saledate=‘94-02-02’ and productid=769. The appropriatefirst-level partition is selected by determining which of partitions104, 106 and 108 is associated with the range into which ‘94-02-02’falls. In the present example, partition 104 is selected. Theappropriate second-level partition is selected by determining which ofsecond-level partitions 110, 112, 114, 116 and 118 is associated withthe hash value produced by productid 769. Assuming that productid 769hashes to hash value H1, partition 110 is selected. Having arrived atthe lowest level of partitioning, the database server stores the rowwithin partition 110.

Composite partitioning can significantly increase the number ofstatements on which partition pruning may be performed. Specifically,with conventional range and hash partitioning, only one partitioning keyis used to partition an object. Consequently, only statements thatselect rows based on that particular partitioning key are candidates forpartition pruning. With composite partitioning, multiple partitioningkeys are used to partition an object, each at a different partitioninglevel. Statements that select rows based on any one of the multiplepartitioning keys are candidates for partition pruning.

For example, assume that a statement selects rows from table 102 where“saledate=94-02-02”. By inspecting the partitioning metadata associatedwith table 102, the database server determines that the selectioncriteria used in the statement uses the first-level partitioning keyassociated with table 102. Consequently, the database server performspartition pruning at the first level. In the present example, thedatabase server determines that 94-02-02 falls within the rangeassociated with first-level partition 104, and therefore excludes fromthe access plan the remainder of the first-level partitions (i.e.partitions 106 and 108).

On the other hand, a statement may select rows from table 102 where“productid=769”. By inspecting the partitioning metadata associated withtable 102, the database server determines that the selection criteriaused in the statement uses the second-level partitioning key associatedwith table 102. Consequently, the database server performs partitionpruning at the second level. In the present example, the database serverdetermines that 769 hashes to hash value H1, associated withsecond-level partitions 110, 120 and 130, and therefore excludes fromthe execution plan of the query the remainder of the second-levelpartitions (i.e. partitions 112-118, 122-128 and 132-138).

A statement may even select rows from table 102 based on bothpartitioning keys. For example, a statement may select rows from table102 where “saledate=94-02-02” and “productid=769”. By inspecting thepartitioning metadata associated with table 102, the database serverdetermines that the selection criteria used in the statement uses thefirst and second-level partitioning keys associated with table 102.Consequently, the database server performs partition pruning at thefirst and second levels. In the present example, the database determinesthat 94-02-02 falls within the range associated with partition 104, andthat 769 hashes to hash value H1, associated with the second-levelpartition 110 within partition 104. Therefore, the database serverexcludes from the execution plan of the query all partitions exceptpartition 110.

Table 102 illustrates one example of composite partitioning, where thepartitioning is performed at two levels, the partitioning technique(e.g. hash or range) is different at each level, and the partitioningkey is different at each level. However, composite partitioning is notlimited to those specifics. For example, a composite partitioned objectmay be partitioned at more than two levels, the partitioning techniquemay be the same at all levels (e.g. all hash or all range) or differfrom level to level, and the various levels may or may not use the samepartitioning key.

PARTITIONING IN SHARED DISK DATABASE SYSTEMS

Databases that run on multi-processing systems typically fall into twocategories: shared disk databases and shared nothing databases. A sharednothing database assumes that a process can only access data if the datais contained on a disk that belongs to the same node as the process.Consequently, in a shared nothing database, work can only be assigned toa process if the data to be processed in the work resides on a disk inthe same node as the process. To store data more evenly among the nodesin a shared nothing database system, large objects are oftenhash-partitioned into a number of hash buckets equal to the number ofnodes in the system. Each partition is then stored on a different node.

A shared disk database expects all disks in the computer system to bevisible to all processing nodes. Shared disk databases may be run onboth shared nothing and shared disk computer systems. To run a shareddisk database on a shared nothing computer system, software support maybe added to the operating system or additional hardware may be providedto allow processes to have direct access to remote disks.

Unlike shared nothing database systems, in shared disk database systems,partitioning is not performed to distribute an object among nodes.Rather, because there is no tie between how an object is partitioned andthe hardware configuration of the system, there are less constraints onhow an object may be partitioned. According to one aspect of theinvention, composite partitioning is performed in shared disk databasesystems in response to user-specified partitioning criteria.Specifically, a user specifies the partitioning criteria to be appliedat each of the multiple levels of a composite partitioned object. Forexample, the following statement is an example of how a user may specifythe creation of a table “sales” that has two levels of partitioning,where the first level is range-based partitioning based on saledate, andthe second level is hash-based partitioning based on productid:

create table sales

(saledate DATE,

productid NUMBER, . . . )

first-level partition by range (saledate)

partition sal94Q1 values less than to_date (yy-mm-dd, ‘94-04-01’)

partition sal94Q2 values less than to_date (yy-mm-dd, ‘94-07-01’)

partition sal94Q3 values less than to_date (yy-mm-dd, ‘94-10-01’)

partition sal94Q4 values less than to_date (yy-mm-dd, ‘95-01-01’)

second-level partition by hash (productid)

partitions 4;

The syntax used in the preceding statement is merely illustrative. Theactual syntax of statements used to define composite partitioned objectsmay vary from implementation to implementation. The present invention isnot limited to any particular syntax.

PARTITION-WISE JOINS

A join is a query that combines rows from two or more tables, views, orsnapshots. A join is performed whenever multiple tables appear in aquery's FROM clause. The query's select list can select any columns fromany of the base tables listed in the FROM clause.

Most join queries contain WHERE clause conditions that compare twocolumns, each from a different table. Such a condition is called a joincondition. To execute a join, the DBMS combines pairs of rows for whichthe join condition evaluates to TRUE, where each pair contains one rowfrom each table.

In addition to join conditions, the WHERE clause of a join query canalso contain other conditions that refer to columns of only one table.These conditions can further restrict the rows returned by the joinquery.

The following query includes a join between two tables, sales andproduct:

select * from sales, product

where sales.productid=product.productid

In this example, both tables contain columns named “productid”. The joincondition in the query causes rows in “sales” to join with rows in“product” when the productid value in the sales rows matches theproductid value in the product rows. Using conventional join techniques,the database server performs the join by comparing every row in thesales table with every row in the product table. Whenever the productidvalue of the sales table row matches the productid value of a productrow, the rows are combined and added to the result set of the join.

According to one aspect of the invention, a technique is provided forperforming joins more efficiently by taking advantage of the fact thatone or more tables involved in a join is partitioned on the same keythat appears in the join condition. For example, FIG. 2 illustrates adatabase 200 in which both a sales table 202 and a product table 204 arepartitioned into four hash partitions, where productid is thepartitioning key. In response to a query that joins tables 202 and 204using productid as the join key, the database server need not compareevery row in sales table 202 against every row in product table 204.Rather, the database server need only compare each row in the salestable 202 to the rows in one partition of product table 204.Specifically, a row in sales table 202 that hashes to a particular hashvalue need only be compared to rows in the partition of product table204 associated with that same hash value. Thus, rows in partition 206 ofsales table are only compared to rows in partition 214 of product table.Rows in partition 208 are only compared to rows in partition 216. Rowsin partition 210 are only compared to rows in partition 218. Rows inpartition 212 are only compared to rows in partition 220.

Joins performed on a partition by partition basis are referred to hereinas partition-wise joins. Partition-wise joins may be performed whenthere is a mapping between the partitions of two partitioned objectsthat are to be joined, where the join key of the join is thepartitioning key for the partitioned objects.

Partition-wise joins may be performed serially or in parallel. Whenperformed serially, data from a partition of a first object is loadedinto volatile memory and joined with the corresponding partition(s) of asecond object. When that join has been performed, another partition ofthe first object is loaded into volatile memory and joined with thecorresponding partition(s) of the second object. This process isrepeated for each partition of the first object. The join rows generatedduring each of the partition-wise join operations are combined toproduce the result-set of the join. Parallel partition-wise joins shallbe described in detail below.

In the example shown in FIG. 2, the mapping between the partitions isone-to-one. However, partition-wise joins are possible when the mappingis not one-to-one. For example, assume that two tables T1 and T2 arepartitioned based on salesdate, but that T1 is partitioned in rangesthat cover individual months, while T2 is partitioned in ranges thatcover quarters. Under these conditions, there is a many-to-one mappingbetween partitions of T1 and partitions of T2. In a partition-wise join,the T1 rows for a particular month are compared to the T2 rows in thepartition that corresponds to the quarter that includes that particularmonth.

Partition-wise joins may even be performed where the boundaries ofpartitions of one table do not coincide with the boundaries ofpartitions of another table. For example, assume that T1 is partitionedinto ranges that cover individual months, while T2 is partitioned intoranges that cover individual weeks. Some weeks span months. In apartition-wise join, the T1 rows for a particular month are compare tothe T2 rows in the partitions that correspond to weeks that have atleast one day in that particular month.

FULL PARALLEL PARTITION-WISE JOINS

One technique for performing a data manipulation operation in parallelis to divide the set of data that is to be manipulated into numeroussubsets of data, and to distribute the subsets to a set of slaveprocesses. In parallel with each other, the slave processes perform therequired manipulation operation on the subsets of data assigned to them.The results produced by each slave are merged to produce the result setof the operation.

One technique for dividing a set of data into subsets, for distributionto slave processes, is through the use of a hash function. The hashfunction is applied on the rows of the table as part of the datamanipulation operation to create the subsets of data. The subsets thuscreated are distributed to slave processes for parallel execution.Unfortunately, creating the subsets as part of the operationsignificantly increases the overhead of the operation.

According to one aspect of the invention, the overhead associated withperforming a parallel data manipulation operation on a partitionedobject is reduced by using the partitions of the object as the subsetsof data for distribution to slave processes. For example, if the producttable 204 is already partitioned as shown in FIG. 2, then operations onproduct table 204 may be performed in parallel by sending data from eachof the partitions to a separate slave process.

When parallelizing join operations, the same hash function must beapplied to each of the joined objects, where the join key of the join isthe hash key used to divide the data into subsets. According to oneaspect of the invention, when a join involves objects that have beenpartitioned using the same hash function, where the join key of the joinis the hash key that was used to partition the objects, then theoverhead associated with performing such joins is reduced by takingadvantage of the pre-existing static partitions of the joined objects.For example, sales table 202 and product table 204 are partitioned onthe same key (productid) using the same hash function. Thus, theexisting partitions of tables 202 and 204 may be used as the subsets ofdata that are distributed to slave processes during execution of a joinbetween tables 202 and 204, where “productid” is the join key. Paralleljoin operations in which the joined objects are partitioned in anidentical manner based on the join key, where the data is divided anddistributed based on the pre-existing static partitions, are referred toherein as full parallel partition-wise joins.

PARTIAL PARALLEL PARTITION-WISE JOINS

The need for both objects in a full parallel partition-wise join to bedivided into subsets using the same criteria poses an obstacle to theuse of pre-established static partitions to parallelize join operations.In particular, situations in which all joined objects happen to bestatically partitioned in the same way based on the join key, such aswas true for tables 202 and 204, are relatively rare. It is much morecommon for at least one of the joined objects to be (1) unpartitioned,(2) partitioned based on a different key, or (3) partitioned based onthe same key but using a different hash function than the object withwhich it is to be joined.

For example, assume that a first table is partitioned into five hashpartitions based on a particular key, and second table is partitionedinto six hash partitions based on the same key. A join between the twotables using that key cannot be performed by distributing work based onthe existing partitions. Specifically, there would be no logicalcorrelation between the partitions of first table and the partitions ofthe second table. Hence, a row in any given partition of the first tablecould potentially combine with rows in any of the partitions of thesecond table.

According to one aspect of the invention, a technique is provided forreducing the overhead associated with performing a parallel joinoperation between objects where a first object is partitioned based onthe join key and the second object is either unpartitioned, partitionedbased on a different key, or partitioned based on the join key but usinga different partitioning criteria than was used to statically partitionthe first object. The technique, referred to herein as a partialparallel partition-wise join, involves dynamically partitioning thesecond object using the same partitioning key and criteria as was usedto create the preexisting static partitions of the first object. Afterthe second object has been dynamically partitioned, the data from eachpartition of the first object is sent to a slave process along with thedata from the corresponding dynamically created partition of the secondobject.

Referring to FIG. 3, it illustrates the performance of a partialparallel partition-wise join between sales table 202 and an inventorytable 300. Unlike tables 202 and 204, inventory table 300 is notpartitioned into four hash partitions based on productid. Rather,inventory table 300 is partitioned into three partitions based onorderdate. A full parallel partition-wise join cannot be performed inresponse to a statement that joins sales table 202 with inventory table300 based on productid because inventory table is not partitioned basedon productid in the same manner as sales table 202. However, theoverhead associated with the join operation may still be reduced byperforming a partial parallel partition-wise join.

In the illustrated example, a partial parallel partition-wise join isperformed by dynamically partitioning inventory table 300 using the samepartition key and criteria that was used to partition sales table 202.Since partition table 202 is partitioned into four partitions based onproductid, the same four-way hash function 304 used to partition salestable 202 is applied to the productid values with the rows of inventorytable 300 to dynamically organize the rows of inventory table into fourhash buckets 330, 332, 334 and 336. Each of the four hash buckets thusproduced is sent, along with the partition of sales table 202 to whichit corresponds, to a separate slave process for parallel execution. Inthe illustrated example, partition 206 and hash bucket 330 (both ofwhich contains rows with productid values that hash to H1) are sent toslave process 310, partition 208 and hash bucket 332 (both of whichcontains rows with productid values that hash to H2) are sent to slaveprocess 312, partition 210 and hash bucket 334 (both of which containsrows with productid values that hash to H3) are sent to slave process314, and partition 212 and hash bucket 336 (both of which contains rowswith productid values that hash to H4) are sent to slave process 316.

In the illustrated example of FIG. 3, the number of slave processes usedto perform the partial parallel partition-wise join is equal to thenumber of partitions of sales table 202. However, this need not be thecase. For example, the same join may be performed using fewer than fourslave processes, in which case one or more of the slave processes wouldbe assigned multiple partitions of sales table 202 along with thecorresponding hash buckets produced from inventory table 300. On theother hand, the number of slave process available to perform theparallel join operation may exceed the number of partitions into whichthe objects have been divided. When the desired degree of parallelismexceeds the number of partitions of the statically-partitioned object, ahash function may be applied to one or more of the partition/hash bucketpairs to divide the partition/hash bucket data into multiple, smallerwork granules. For example, a two way hash function may be applied topartition 206 and hash bucket 330, where rows from one of the two hashbuckets thus produced would be processed by slave process 310, and rowsfrom the other of the two hash buckets would be processed by a fifthslave process (not shown).

According to one embodiment of the invention, the process of dynamicallypartitioning one object in the same manner as a statically partitionedobject during a partial parallel partition-wise join is itselfdistributed among slave processes for parallel execution. For example,each of four slave processes may be assigned to scan portions ofinventory table 300. Each of the four slaves applies the hash function304 to the rows that it scans, and adds the rows to the appropriate hashbucket. The process of adding a row to a hash bucket may involve, forexample, transmitting the row to the slave process that, at the nextphase of the partial parallel partition-wise join, is responsible forhandling rows from that hash bucket. For example, a hash-operation slavemay add a row to the hash bucket for H1 by sending the row to slaveprocess 310.

Frequently, the slave process that is responsible for determining thehash bucket for a particular row is on a different node than the slaveprocess that is responsible for joining rows from that hash bucket.Consequently, the transmission of the row from one slave to the otheroften involves inter-node communication, which has a significant impacton performance. Thus, a significant benefit achieved by partial parallelpartition-wise joins is that data from only one of the two objectsinvolved in the join is dynamically partitioned, and therefore mayrequire inter-node transmission. Rows from the statically partitionedobject, on the other hand, may simply be loaded from disk directly intothe node on which resides the slave process responsible for processingthe partition in which the rows reside. The larger thestatically-partitioned object, the greater the performance gain achievedby avoiding the inter-node transmission of data from thestatically-partitioned object.

NON-TABLE OBJECTS

In the embodiments described above, the objects being joined are tables.However, the present invention is not limited to joins between tables.For example, a partial parallel partition-wise join may be performedwhen the statically partitioned object is an index, and the object withwhich the index is joined is a table.

PARTIAL PARALLEL PARTITION-WISE JOINS OF COMPOSITE PARTITIONED OBJECTS

When the statically-partitioned object in a partial parallelpartition-wise join is an object that has been partitioned usingcomposite partitioning, multiple different partitioning criteria may beavailable for use in the join. For example, a statically partitionedobject (SPO) may be partitioned at the first level using range-basedpartitioning on the join key, and at a second level using hash-basedpartitioning on the join key. Under these conditions, it is possible toperform a partial parallel partition-wise join with another object (DPO)by dynamically partitioning DPO either based on the same range-basedpartitioning criteria that was used to perform the first levelpartitioning of SPO, or based on the same hash function that was used toperform the second level partitioning of SPO.

Typically, when choosing the partitioning technique to use to distributework for a parallel operation, hash-based partitioning is generallypreferred over range-based partitioning because of the reducedlikelihood of skew. Because hash-based partitions are less likely toexhibit skew, it is more likely that slave processes assigned work basedon hash-buckets will be responsible for approximately the same amount ofwork, and therefore will finish their tasks at approximately the sametime.

PARTIAL PARALLEL PARTITION-WISE JOINS WITH PRUNING

When the statically-partitioned object in a partial parallelpartition-wise join is an object that has been partitioned usingcomposite partitioning, it may be possible to perform partition pruningbased on a different level of partitioning than is used to distributethe data during the partial parallel partition-wise join. For example,assume that a query specifies a join between table 102 illustrated inFIG. 1 and a non-partitioned table NPT, where the join key is productid.However, in addition to the join condition, the query includes thecondition “saledate<94-05-01”. Under these conditions, the databaseserver performs partition pruning on the first-level partitions 104, 106and 108 of table 102 based on the “saledate<94-05-01” condition. In thecurrent example, during the partition pruning the database server wouldeliminate from consideration partition 108, which is associated with asaledate range that could not possibly satisfy the “saledate<94-05-01”condition.

After pruning has been performed based on first-level partitions 104,106 and 108, parallel distribution of work can be performed based on thesecond-level hash partitions. That is, slave processes are assigned workon a per-hash-bucket basis, where the hash buckets are produced by thehash function used to perform the second-level partitioning of table102. For the purpose of explanation, it shall be assumed that five slaveprocesses are to be used to perform the join between table 102 and tableNPT. Consequently, each of those five processes will be assigned thedata associated with a particular hash value.

Only those second-level hash partitions that remain after pruning aredistributed to slave processes. In the present example, first-levelpartition 108 was pruned. Consequently, the data in the second-levelhash partitions 130, 132, 134, 136 and 138 that reside in partition 108is not distributed to the slave processes. Of the secondlevel-partitions that belong to the remaining first-level partitions 104and 106:

the second-level partition 110 of partition 104 that is associated withhash value H1, and the second-level partition 120 of partition 106 thatis associated with hash value H1, are both assigned to a first slaveprocess,

the second-level partition 112 of partition 104 that is associated withhash value H2, and the second-level partition 122 of partition 106 thatis associated with hash value H2, are both assigned to a second slaveprocess,

the second-level partition 114 of partition 104 that is associated withhash value H3, and the second-level partition 124 of partition 106 thatis associated with hash value H3, are both assigned to a third slaveprocess,

the second-level partition 116 of partition 104 that is associated withhash value H4, and the second-level partition 126 of partition 106 thatis associated with hash value H4, are both assigned to a fourth slaveprocess,

the second-level partition 118 of partition 104 that is associated withhash value H5, and the second-level partition 128 of partition 106 thatis associated with hash value H5, are both assigned to a fifth slaveprocess.

During execution of the partial parallel partition-wise join betweentable 102 and NPT, NPT is dynamically partitioned using the same hashfunction as was used to create the static second-level partitions oftable 102. The application of the hash function to NPT produces fivehash buckets, where rows from the hash buckets associated with hashvalues H1, H2, H3, H4 and H5 are respectively sent to the first, second,third, fourth and fifth slave processes.

In the example given above, pruning was done based on the first-levelpartitioning of a composite partitioned object, while data distributionto slave processes was done based on the second-level partitioning.However, any level or levels of a composite partitioned object may beused for pruning, and any level may be used for parallel datadistribution. For example, pruning may be performed using partitionlevels two, five, six and eight of an eight-way partitioned object,while any one of the eight partitions may be used for distributing thedata to slave processes during a parallel join operation. Further, thepartition level used to distribute the data need not be ahash-partitioned level, but may, for example, be a range-partitionedlevel.

HARDWARE OVERVIEW

FIG. 4 is a block diagram that illustrates a computer system 400 uponwhich an embodiment of the invention may be implemented. Computer system400 includes a bus 402 or other communication mechanism forcommunicating information, and a processor 404 coupled with bus 402 forprocessing information. Computer system 400 also includes a main memory406, such as a random access memory (RAM) or other dynamic storagedevice, coupled to bus 402 for storing information and instructions tobe executed by processor 404. Main memory 406 also may be used forstoring temporary variables or other intermediate information duringexecution of instructions to be executed by processor 404. Computersystem 400 further includes a read only memory (ROM) 408 or other staticstorage device coupled to bus 402 for storing static information andinstructions for processor 404. A storage device 410, such as a magneticdisk or optical disk, is provided and coupled to bus 402 for storinginformation and instructions.

Computer system 400 may be coupled via bus 402 to a display 412, such asa cathode ray tube (CRT), for displaying information to a computer user.An input device 414, including alphanumeric and other keys, is coupledto bus 402 for communicating information and command selections toprocessor 404. Another type of user input device is cursor control 416,such as a mouse, a trackball, or cursor direction keys for communicatingdirection information and command selections to processor 404 and forcontrolling cursor movement on display 412. This input device typicallyhas two degrees of freedom in two axes, a first axis (e.g., x) and asecond axis (e.g., y), that allows the device to specify positions in aplane.

The invention is related to the use of computer system 400 forpartitioning, partition pruning and performing partition-wise joinsaccording to the techniques described herein. According to oneembodiment of the invention, those techniques are implemented bycomputer system 400 in response to processor 404 executing one or moresequences of one or more instructions contained in main memory 406. Suchinstructions may be read into main memory 406 from anothercomputer-readable medium, such as storage device 410. Execution of thesequences of instructions contained in main memory 406 causes processor404 to perform the process steps described herein. In alternativeembodiments, hard-wired circuitry may be used in place of or incombination with software instructions to implement the invention. Thus,embodiments of the invention are not limited to any specific combinationof hardware circuitry and software.

The term “computer-readable medium” as used herein refers to any mediumthat participates in providing instructions to processor 404 forexecution. Such a medium may take many forms, including but not limitedto, non-volatile media, volatile media, and transmission media.Non-volatile media includes, for example, optical or magnetic disks,such as storage device 410. Volatile media includes dynamic memory, suchas main memory 406. Transmission media includes coaxial cables, copperwire and fiber optics, including the wires that comprise bus 402.Transmission media can also take the form of acoustic or light waves,such as those generated during radio-wave and infra-red datacommunications.

Common forms of computer-readable media include, for example, a floppydisk, a flexible disk, hard disk, magnetic tape, or any other magneticmedium, a CD-ROM, any other optical medium, punchcards, papertape, anyother physical medium with patterns of holes, a RAM, a PROM, and EPROM,a FLASH-EPROM, any other memory chip or cartridge, a carrier wave asdescribed hereinafter, or any other medium from which a computer canread.

Various forms of computer readable media may be involved in carrying oneor more sequences of one or more instructions to processor 404 forexecution. For example, the instructions may initially be carried on amagnetic disk of a remote computer. The remote computer can load theinstructions into its dynamic memory and send the instructions over atelephone line using a modem. A modem local to computer system 400 canreceive the data on the telephone line and use an infra-red transmitterto convert the data to an infra-red signal. An infra-red detector canreceive the data carried in the infra-red signal and appropriatecircuitry can place the data on bus 402. Bus 402 carries the data tomain memory 406, from which processor 404 retrieves and executes theinstructions. The instructions received by main memory 406 mayoptionally be stored on storage device 410 either before or afterexecution by processor 404.

Computer system 400 also includes a communication interface 418 coupledto bus 402. Communication interface 418 provides a two-way datacommunication coupling to a network link 420 that is connected to alocal network 422. For example, communication interface 418 may be anintegrated services digital network (ISDN) card or a modem to provide adata communication connection to a corresponding type of telephone line.As another example, communication interface 418 may be a local areanetwork (LAN) card to provide a data communication connection to acompatible LAN. Wireless links may also be implemented. In any suchimplementation, communication interface 418 sends and receiveselectrical, electromagnetic or optical signals that carry digital datastreams representing various types of information.

Network link 420 typically provides data communication through one ormore networks to other data devices. For example, network link 420 mayprovide a connection through local network 422 to a host computer 424 orto data equipment operated by an Internet Service Provider (ISP) 426.ISP 426 in turn provides data communication services through the worldwide packet data communication network now commonly referred to as the“Internet” 428. Local network 422 and Internet 428 both use electrical,electromagnetic or optical signals that carry digital data streams. Thesignals through the various networks and the signals on network link 420and through communication interface 418, which carry the digital data toand from computer system 400, are exemplary forms of carrier wavestransporting the information.

Computer system 400 can send messages and receive data, includingprogram code, through the network(s), network link 420 and communicationinterface 418. In the Internet example, a server 430 might transmit arequested code for an application program through Internet 428, ISP 426,local network 422 and communication interface 418. The received code maybe executed by processor 404 as it is received, and/or stored in storagedevice 410, or other non-volatile storage for later execution. In thismanner, computer system 400 may obtain application code in the form of acarrier wave.

In the foregoing specification, the invention has been described withreference to specific embodiments thereof. It will, however, be evidentthat various modifications and changes may be made thereto withoutdeparting from the broader spirit and scope of the invention. Thespecification and drawings are, accordingly, to be regarded in anillustrative rather than a restrictive sense.

What is claimed is:
 1. A method for processing a statement thatspecifies a join between a first object and a second object based on ajoin key, the method comprising the steps of: performing multi-levelstatic partitioning of the first object, including performing the stepsof: statically partitioning the first object at a first level byapplying a first partitioning criteria to the first object to produce afirst set of partitions; and statically partitioning the first object ata second level based on said join key, wherein the static partitioningbased on said join key is performed by applying a second partitioningcriteria to each partition in said first set of partitions to produce asecond set of partitions; during execution of said statement, using thesecond level of static partitioning of said first object as a basis fordistributing data of said first object, including performing the stepsof: inspecting partitioning metadata based on said statement todetermine that the second level of static partitioning of said firstobject, and not said first level of static partitioning, should be usedas a basis for distributing data from said first object to a pluralityof slave processes; distributing data from said first and second objectsto each slave process of said plurality of slave processes based on saidsecond partitioning criteria, including distributing to each slaveprocess of said plurality of slave processes a first subset of data fromsaid first object, wherein the first subset of data that is distributedto each slave process is established based on said second set ofpartitions; distributing to each slave process of said plurality ofslave processes a second subset of data from said second object, whereinthe second subset of data that is distributed to each slave process isestablished based on said second partitioning criteria; and causing eachslave process of said plurality of slave processes to perform a joinbetween the first subset of data assigned to the slave process and thesecond subset of data assigned to the slave process.
 2. The method ofclaim 1 wherein: the second object is statically partitioned based onthe second partitioning criteria; and no dynamic partitioning isperformed to establish the first and second subsets of data that aredistributed to each slave process.
 3. The method of claim 1 wherein: thesecond object is not statically partitioned based on the secondpartitioned criteria; and the method further comprises the step of, inresponse to said statement, dynamically partitioning the second objectbased on the same partitioning criteria used to statically partitionsaid first object.
 4. The method of claim 1 wherein the method furtherincludes the step of establishing said first and second subsets of datato distribute to each slave process based on said second partitioningcriteria.
 5. The method of claim 1 wherein the method further includesthe steps of: performing partition pruning based on one partitioningcriteria of said first partitioning criteria and said secondpartitioning criteria; and establishing said first and second subsets ofdata to distribute to each slave process based on the other partitioningcriteria of said first partitioning criteria and said secondpartitioning criteria.
 6. A computer readable medium bearinginstructions for processing a statement that specifies a join between afirst object and a second object based on a join key, the instructionsincluding instructions for performing the steps of: performingmulti-level static partitioning of the first object, includingperforming the steps of: statically partitioning the first object at afirst level by applying a first partitioning criteria to the firstobject to produce a first set of partitions; and statically partitioningthe first object at a second level based on said join key, wherein thestatic partitioning based on said join key is performed by applying asecond partitioning criteria to each partition in said first set ofpartitions to produce a second set of partitions; during execution ofsaid statement, using the second level of static partitioning of saidfirst object as a basis for distributing data of said first object,including performing the steps of: inspecting partitioning metadatabased on said statement to determine that the second level of staticpartitioning of said first object, and not said first level of staticpartitioning, should be used as a basis for distributing data from saidfirst object to a plurality of slave processes; distributing data fromsaid first and second objects to each slave process of said plurality ofslave processes based on said second partitioning criteria, includingdistributing to each slave process of said plurality of slave processesa first subset of data from said first object, wherein the first subsetof data that is distributed to each slave process is established basedon said second set of partitions; distributing to each slave process ofsaid plurality of slave processes a second subset of data from saidsecond object, wherein the second subset of data that is distributed toeach slave process is established based on said second partitioningcriteria; and causing each slave process of said plurality of slaveprocesses to perform a join between the first subset of data assigned tothe slave process and the second subset of data assigned to the slaveprocess.
 7. The computer readable medium of claim 6 wherein: the secondobject is statically partitioned based on the same partitioning criteriaused to statically partition said first object, and no dynamicpartitioning is performed to establish the first and second subsets ofdata that are distributed to each slave process.
 8. The computerreadable medium of claim 6 wherein: the second object is not staticallypartitioned based on the same partitioning criteria used to staticallypartition said first object; and the instructions further includeinstructions for performing the step of, in response to said statement,dynamically partitioning the second object based on the samepartitioning criteria used to statically partition said first object. 9.The computer readable medium of claim 6 wherein the instructions furtherinclude instructions for performing the step of establishing said firstand second subsets of data to distribute to each slave process based onsaid second partitioning criteria.
 10. The computer readable medium ofclaim 6 wherein the instructions further include instructions forperforming the steps of: performing partition pruning based on onepartitioning criteria of said first partitioning criteria and saidsecond partitioning criteria; and establishing said first and secondsubsets of data to distribute to each slave process based on the otherpartitioning criteria of said first partitioning criteria and saidsecond partitioning criteria.